*** Robustness table: sample of neighbouring municipalities ***

** Preamble **

clear all
set more off

local path_input  "C:/Users/$user/Dropbox/$project/master/output/data"
local path_output "C:/Users/$user/Dropbox/$project/master/output/tables"


* Note: local directory is the output folder 
cd "`path_output'"

local baseline_controls "pop1991 years_sch1991 renda1991 sh_tv1991 sh_agua1991 sh_elect1991 sh_rural"

					** Loading the input file **

use `path_input'/dataset_final_may20, clear

estimates clear

xtset codigo_ibge turno

local baseline_controls "pop1991 years_sch1991 renda1991 sh_tv1991 sh_agua1991 sh_elect1991 sh_rural"
local CGB_FEs			"pct_sh_tv1991 pct_sh_rural pct_renda1991"


/*generating percentiles*/
foreach var in `baseline_controls' {
xtile pct_`var'=  `var', n(10)
replace pct_`var'=0 if turno==2
}

/*generating pscores*/
encode uf, gen(UF)
psmatch2 Globo T1* if turno==1,  noreplace neighbor(1)
egen ppp=mean(_pscore), by(codigo)
gen pscore=1
replace pscore=ppp/(1-ppp) if Globo==0

label var treatment  "Globo"
label var treatment1 "Globo and Others"
label var treatment2 "Globo Only"

foreach v of varlist * {

	label variable `v' `"\hspace{0.1cm} `: variable label `v''"'
	
}



										** Table: Results exclusing RS and RJ ** 
										
/*
The table reports regression estimates of the effect of Globo's edited coverage on the second round's vote shares in the 1989 presidential elections. Odd-numbered columns report estimates on Lula's vote share and even-numbered columns on Collor's one. All specification controls for municipality and time fixed effects.  Columns (1) to (4) report estimates for the full sample and (5) to (8) exclude the states of Rio de Janeiro, and Rio Grande do Sul.  Heteroskedasticity-adjusted standard errors clustered at the municipality level are reported in brackets. Significantly different from zero at $99\% (***)$, $95\% (**)$ and $90\% (*)$ confidence level.
*/

local legend "The table reports regression estimates of the effect of Globo's edited coverage on the second round's vote shares in the 1989 presidential elections. Odd-numbered columns report estimates on Lula's vote share and even-numbered columns on Collor's one. All specification controls for municipality and time fixed effects.  Columns (1) to (4) report estimates for the full sample and (5) to (8) exclude the states of Rio de Janeiro, and Rio Grande do Sul.  Heteroskedasticity-adjusted standard errors clustered at the municipality level are reported in brackets. Significantly different from zero at $99\% (***)$, $95\% (**)$ and $90\% (*)$ confidence level."


										** Panel A **

eststo: xi: reghdfe sh_Tpt_  treatment 			   		  turno, vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tprn_ treatment 			   		  turno, vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tpt_  treatment sh_Tpsp_-sh_Tpsdb_ turno, vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"

eststo: xi: reghdfe sh_Tprn_ treatment sh_Tpsp_-sh_Tpsdb_ turno, vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"


eststo: xi: reghdfe sh_Tpt_  treatment 			   		  turno if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tprn_ treatment 			   		  turno if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tpt_  treatment sh_Tpsp_-sh_Tpsdb_ turno if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"

eststo: xi: reghdfe sh_Tprn_ treatment sh_Tpsp_-sh_Tpsdb_ turno if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"


										** Panel B **

eststo: xi: reghdfe sh_Tpt_  treatment 			   		  turno, vce(cluster codigo_ibge) a(codigo_ibge `CGB_FEs')
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tprn_ treatment 			   		  turno, vce(cluster codigo_ibge) a(codigo_ibge `CGB_FEs')
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tpt_  treatment sh_Tpsp_-sh_Tpsdb_ turno, vce(cluster codigo_ibge) a(codigo_ibge `CGB_FEs')
estadd local PartiesControl "Yes"

eststo: xi: reghdfe sh_Tprn_ treatment sh_Tpsp_-sh_Tpsdb_ turno, vce(cluster codigo_ibge) a(codigo_ibge `CGB_FEs')
estadd local PartiesControl "Yes"


eststo: xi: reghdfe sh_Tpt_  treatment 			   		  turno if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge `CGB_FEs')
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tprn_ treatment 			   		  turno if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge `CGB_FEs')
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tpt_  treatment sh_Tpsp_-sh_Tpsdb_ turno if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge `CGB_FEs')
estadd local PartiesControl "Yes"

eststo: xi: reghdfe sh_Tprn_ treatment sh_Tpsp_-sh_Tpsdb_ turno if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge `CGB_FEs')
estadd local PartiesControl "Yes"

										** Panel C **

eststo: xi: reghdfe sh_Tpt_  treatment 			   		  turno [pw=pscore], vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tprn_ treatment 			   		  turno [pw=pscore], vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tpt_  treatment sh_Tpsp_-sh_Tpsdb_ turno [pw=pscore], vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"

eststo: xi: reghdfe sh_Tprn_ treatment sh_Tpsp_-sh_Tpsdb_ turno [pw=pscore], vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"


eststo: xi: reghdfe sh_Tpt_  treatment 			   		  turno [pw=pscore] if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tprn_ treatment 			   		  turno [pw=pscore] if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "No"

eststo: xi: reghdfe sh_Tpt_  treatment sh_Tpsp_-sh_Tpsdb_ turno [pw=pscore] if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"

eststo: xi: reghdfe sh_Tprn_ treatment sh_Tpsp_-sh_Tpsdb_ turno [pw=pscore] if (uf!="RJ" & uf!="RS"), vce(cluster codigo_ibge) a(codigo_ibge)
estadd local PartiesControl "Yes"


									*** Producing the table ***
																								
esttab est1 est2 est3 est4 est5 est6 est7 est8 using Table_robustness_excluding_panel_A.tex, ///
keep(treatment) ///
order(treatment) ///
stat(N r2, fmt(0 2) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{S}{@}") label("Observations" "R-squared")) ///
mgroups("Full sample" "Excluding RJ and RS states" , pattern(1 0 0 0 1 0 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cline{@span})) ///
star(* 0.10 ** 0.05 *** 0.01) ///
r2 b(3) replace  se(3) brac compress nonotes label nogaps staraux nomtitles  ///
nonotes addnotes("\begin{minipage}{.85\linewidth} \footnotesize \smallskip \textbf{Note:} `legend' \end{minipage}" )


esttab est9 est10 est11 est12 est13 est14 est15 est16 using Table_robustness_excluding_panel_B.tex, ///
keep(treatment) ///
order(treatment) ///
stat(N r2, fmt(0 2) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{S}{@}") label("Observations" "R-squared")) ///
mgroups("Full sample" "Excluding RJ and RS states" , pattern(1 0 0 0 1 0 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cline{@span})) ///
star(* 0.10 ** 0.05 *** 0.01) ///
r2 b(3) replace  se(3) brac compress nonotes label nogaps staraux nomtitles   ///
nonotes addnotes("\begin{minipage}{.85\linewidth} \footnotesize \smallskip \textbf{Note:} `legend' \end{minipage}" )


esttab est17 est18 est19 est20 est21 est22 est23 est24 using Table_robustness_excluding_panel_C.tex, ///
keep(treatment) ///
order(treatment) ///
stat(N r2 Space PartiesControl, fmt(0 2 0 0) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{S}{@}" "\multicolumn{1}{S}{@}" "\multicolumn{1}{c}{@}") ///
label("Observations" "R-squared" " " "Electoral controls * Round")) ///
mgroups("Full sample" "Excluding RJ and RS states" , pattern(1 0 0 0 1 0 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cline{@span})) ///
star(* 0.10 ** 0.05 *** 0.01) ///
r2 b(3) replace  se(3) brac compress nonotes label nogaps staraux nomtitles ///
nonotes addnotes("\begin{minipage}{.85\linewidth} \footnotesize \smallskip \textbf{Note:} `legend' \end{minipage}" )

include "https://raw.githubusercontent.com/steveofconnell/PanelCombine/master/PanelCombine.do"

panelcombine, use(Table_robustness_excluding_panel_A.tex Table_robustness_excluding_panel_B.tex Table_robustness_excluding_panel_C.tex) ///
paneltitles("Unweighted, no FEs" "Group FEs" "Reweighted") columncount(5) save(results_Lula_Collor_without_RJ_RS.tex) cleanup


										

